<template>
  <div>
    <div class="l">
      <div id="main"></div>
    </div>
    <div class="l">
      <div id="main1"></div>
    </div>
    <div class="l">
      <div id="main2"></div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import $ from "jquery";
export default {
  data() {
    return {};
  },
  mounted() {
    let that=this
    that.b();
    // that.c();
    //请求数据
    let p = new Promise((resolve, reject) => {
      $.ajax({
        url: `https://view.inews.qq.com/g2/getOnsInfo?name=disease_foreign`,
        dataType: "jsonp",
        success:(res)=> {
          resolve(res);
        },
        error:(err)=> {
          reject(err);
        },
      });
    });
    p.then((res) => {//左一
         console.log(res);
          let data = JSON.parse(res.data);
          console.log(data,'11')
      let leftDom1 = document.getElementById("main");
      let main = that.action(data.countryAddConfirmRankList);
      that.addCharts(leftDom1, main);

      //左二
      let leftDom2 = document.getElementById("main1");
      let left2 = that.leftTwo(data.continentStatis);
        console.log(data.globalDailyHistory,'2');
      that.addCharts2(leftDom2, left2);
   });
    p.then((res) => {//左三
         console.log(res);
          let data = JSON.parse(res.data);
      // console.log(res.countryAddConfirmRankList);
      let leftDom3 = document.getElementById("main2");
      let left3 = that.leftThree(data.continentStatis);
      that.addCharts3(leftDom3,left3);
    });
  },
  methods: {
       addCharts2(dom, option) {//左二
      let myChart = echarts.init(dom);
      myChart.setOption(option); //监听
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
    // leftTwo(value){
   
    // },
      leftTwo(continentStatis) {
			let series = []
			let date = [];
			let data = [
				{
					num: [],
					lineColor: "#f8b448",
					name: "亚洲",
				},
				{
					num: [],
					lineColor: "#f57474",
					name: "北美洲",
				},
				{
					num: [],
					lineColor: "#1089e7",
					name: "大洋洲",
				},
				{
					num: [],
					lineColor: "#f0af47",
					name: "欧洲",
				},

				{
					num: [],
					lineColor: "#5c55b1",
					name: "其他",
				},
			]
			//循环筛选出各洲感染人数,日期
			continentStatis.forEach(item => {
				date.push(item.date)

				data.forEach(ite => {
					Object.keys(item.statis).forEach(key => {
						if (ite.name == key) {
							ite.num.push(item.statis[key])
							return false
						}
					})
					if (!item.statis.hasOwnProperty(ite.name)) {
						ite.num.push(0)
					}
				})

			})
			//给series添加数据
			data.forEach(item => {
				series.push(
					{
						name: item.name,
						type: 'line',
						smooth: true,
						// symbol: 'circle',
						symbolSize: 4,
						itemStyle: {
							normal: {
								//上显示数值
								label: {
									show: false
								},
								borderColor: item.lineColor,  //边框颜色
								borderBackgroundColor: "#fff",
								lineStyle: {
									width: 2,  // 设置线宽
									type: 'solid',
									color: item.lineColor
								}
							}
						},
						data: item.num
					}
				)
			})

			let optionL2 = {
				grid: {
					top: '70',
          // bottom:'30',
          left:'10',
					x: "70",
					y: "200",
					y2: "30"
				},
				tooltip: {
					trigger: 'axis',
					axisPointer: {
						lineStyle: {
							color: {
								type: 'linear',
								x: 0,
								y: 0,
								x2: 0,
								y2: 1,
								global: false
							}
						},
					},
				},

				legend: {
				      top:'15%',
        data: ['亚洲', '北美洲','大洋洲','欧洲','其他'],
					textStyle: {
						color: '#c1cadf',
						fontSize: 10,
					},
          
				},
    //              legend: {
    //   top:'15%',
    //     data: ['死亡人数', '治愈人数'],
    //         textStyle:{//图例文字的样式
    //         color:'#ccc',
    //         fontSize:10
    //     }
    // },
				xAxis: [{

					type: 'category',
					axisLine: {
						lineStyle: {
							color: '#44607C'
						}
					},
					axisLabel: {
						show: true,
						margin: 10,
            interval:10,
						textStyle: {
							fontSize: 10,
							color: '#4c9bfd',
						},
					},
					axisTick: {
						show: false
					},
					data: date
				}],
				yAxis: [{
					type: 'value',
					splitNumber: 5,	//Y轴平均分割
					min: 0,
					max: 50000000,
					axisTick: {
						show: false
					},
					axisLine: {
						lineStyle: {
							color: 'none'
						}
					},
					axisLabel: {
						margin: 10,
						textStyle: {
							fontSize: 10,
							color: '#4c9bfd',
						},
					},
					splitLine: {
						lineStyle: {
							color: '#57617B'
						}
					}
				}],
				series: series
			};
			return optionL2
		},
     addCharts3(dom, option) {//左三
      let myChart = echarts.init(dom);
      myChart.setOption(option); //监听
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
    leftThree(value){
       let sj=[];
       let sj1=[]
       for(let item of value){
          sj.push(item.statis['北美洲'])
          sj1.push(item.statis['欧洲'])
       }
       let option={
           title: {
          top: "0%",
          left: "90px",
          text: "大洲感染人数饼状图",
          textStyle: {
            align: "center",
            color: "white",
            fontSize: 15,
            fontWeight: 400,
          },
        },
        tooltip: {
          trigger: "item",
        },
          legend: {
            bottom: '5%',
            left: 'center',
            textStyle:{//图例文字的样式
            color:'#ccc',
            fontSize:10
        }
          },
        series: [
          {
            name: "各州感染人数",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "20",
                fontWeight: "bold",
                color: "white",
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: sj, name: "北美洲" },
              { value: sj1, name: "欧洲" },
            ],
          },
        ],
       }
       return option
    },
    addCharts(dom, option) {//左一
      let myChart = echarts.init(dom);
      myChart.setOption(option); //监听
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
    action(value) {//左一
      let xAxis = [];
      let yAxis = [];
        for (let item of value) {
          xAxis.push(item.nation);
        yAxis.push(item.addConfirm);
        }
      let option = {
          title: {
               top: "0%",
               left: "110px",
               text: "新增确诊TOP10",
               textStyle: {
                  align: "center",
                  color: "white",
                  fontSize: 15,
                  fontWeight: 400,
               },
            },
        // backgroundColor: '#00265f',
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          top: "15%",
          right: "3%",
          left: "15%",
          bottom: "12%",
        },
        xAxis: [
          {
            type: "category",
            data: xAxis,
            axisLine: {
              lineStyle: {
                color: "rgba(255,255,255,0.12)",
              },
            },
            axisLabel: {
              margin: 10,
              color: "#e2e9ff",
              textStyle: {
                fontSize: 10,
              },
            },
          },
        ],
        yAxis: [
          {
            axisLabel: {
              formatter: "{value}",
              color: "#e2e9ff",
            },
            // axisLine: {
            //   show: false,
            // },
            splitLine: {
              lineStyle: {
              color: 'rgba(255,255,255,0.12)'
              }
            },
          },
        ],
        series: [
          {
            type: "bar",
            data: yAxis,
            barWidth: "10",
            itemStyle: {
              normal: {
                color: "rgba(0,77,167,1)", // 100% 处的颜色
                barBorderRadius: [30, 30, 30, 30],
                shadowColor: "rgba(0,160,221,1)",
                shadowBlur: 4,
              },
            },
            label: {
              // normal: {
              //   show: true,
              //   lineHeight: 30,
              //   // width: 80,
              //   height: 30,
              //   backgroundColor: "rgba(0,160,221,0.1)",
              //   borderRadius: 200,
              // },
            },
          },
        ],
      };

      return option;
    },//左一end
    b() {
      //左二
      var chartDom = document.getElementById("main1");
      var myChart = echarts.init(chartDom);
      var option;

      option = {
         title: {
          top: "0%",
          left: "100px",
          text: "大洲感染总人数趋势图",
          textStyle: {
            align: "center",
            color: "white",
            fontSize: 15,
            fontWeight: 400,
          },
        },
    color: ['#D53A35', '#E98F6F', '#6AB0B8', '#334B5C'],
    //title: {
    //    text: '报警次数'
    //},
    // tooltip: {
    //     trigger: 'axis',
    //     //formatter: "{b} <br> 合格率: {c}%"
    // },
    legend: {
      top:'12%',
        data: ['亚洲', '班线运输', '危险品', '普货'],
            textStyle:{//图例文字的样式
            color:'#ccc',
            fontSize:10
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    // toolbox: {
    //     feature: {
    //         saveAsImage: {}
    //     }
    // },
    xAxis: {
        type: 'category',
        name: '日期',
        boundaryGap: false,
            axisLine: {
              lineStyle: {
                color:'white'
              },
        },
        data: ['5.1', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7']
    },
    yAxis: {
        type: 'value',
        // name: '报警次数',
            axisLine: {
              lineStyle: {
                color:'white'
              },
            }
    },
    series: [{
            name: '亚洲',
            type: 'line',
            stack: '总量',
            data: [120, 132, 101, 134, 90, 230, 210]
        },
        {
            name: '班线运输',
            type: 'line',
            stack: '总量',
            data: [220, 182, 191, 234, 290, 330, 310]
        },
        {
            name: '危险品',
            type: 'line',
            stack: '总量',
            data: [150, 232, 201, 154, 190, 330, 410]
        },
        {
            name: '普货',
            type: 'line',
            stack: '总量',
            data: [320, 332, 301, 334, 390, 330, 320]
        },
    ]
};
      option && myChart.setOption(option);
    }, //end
  },
};
</script>

<style lang="scss">
.l {
  width: 510px;
  height: 310px;
  // padding: 10px 20px;

  position: relative;

  margin-top: 10px;
  background: linear-gradient(to top, #306eef, #306eef) left top no-repeat,
    /*上左*/ linear-gradient(to right, #306eef, #306eef) left top no-repeat,
    /*左上*/ linear-gradient(to left, #306eef, #306eef) right top no-repeat,
    /*上右*/ linear-gradient(to bottom, #306eef, #306eef) right top no-repeat,
    /*上右*/ linear-gradient(to left, #306eef, #306eef) left bottom no-repeat,
    /*下左*/ linear-gradient(to bottom, #306eef, #306eef) left bottom no-repeat,
    /*左下*/ linear-gradient(to top, #306eef, #306eef) right bottom no-repeat,
    /*下右*/ linear-gradient(to left, #306eef, #306eef) right bottom no-repeat; /*右下*/
  background-size: 2px 16px, 16px 2px, 2px 16px, 16px 2px;
  #main {
    //     width: 100%;
    // height: 100%;
    width: 500px;
    height: 300px;
    left: 5px;
    top: 5px;
    position: absolute;
  }
  #main1 {
    //     width: 100%;
    // height: 100%;
    width: 500px;
    height: 300px;
    left: 5px;
    top: 5px;
    position: absolute;
  }
  #main2 {
    //     width: 100%;
    // height: 100%;
    width: 500px;
    height: 300px;
    left: 5px;
    top: 5px;
    position: absolute;
  }
}
</style>